/**
 * @description chat数据库操作
 * @author 盘古他爹
 */
import { Chat } from "../../model/chat"
import { User } from "../../model/user"
import ResponseModel from "../../config/response.config"

enum myHe {
    my = "my",
    he = "he"
}

interface IContent {
    time: string
    my?: string
    he?: string
}

interface IChatRecord {
    id: number
    userId: number
    friend: number
    content: string
    status: boolean
    createdAt: string
    updatedAt: string
}




class ChatService {
    async getFrinedLists(id: number) {
        const res = await User.findAll({
            include: {
                model: Chat,
                where: {
                    userId: id
                },
                attributes: []
            }
        })
        if (res.length > 0) {

            return res
            // ResponseModel.success({ list: res }, "获取成功")
        }
        console.log("res", res);

        // return `${id}去寻找朋友`
    }

    //获取与某一好友聊天记录
    async getFriendChatRecord(userId: number, friendId: number) {
        console.log("userId:", userId);
        console.log("friendId:", friendId);


        const res = await Chat.findOne({
            where: {
                userId,
                friend: friendId,
                status: true
            },
            // attributes: ["content"]
        })

        if (res) {

            res.content = JSON.parse(res.content)
            console.log("res", res);
            return res.dataValues

        }

    }


}


export default new ChatService()